package com.bm.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bm.server.dto.UserSearchDto;
import com.bm.server.util.Rutils;
import com.bm.server.vo.R;
import com.bm.server.dao.AllySearchDao;
import com.bm.server.dao.RoomSearchDao;
import com.bm.server.dao.UserSerachDao;
import com.bm.server.entity.Ally;
import com.bm.server.entity.RoomHead;
import com.bm.server.service.intf.SearchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: 赵金帅
 * @Date: 2022/07/19/0:21
 */
@Service
public class SearchServiceimpl implements SearchService {
    @Resource
    private AllySearchDao dao;
    @Resource
    private RoomSearchDao roomdao;
    @Resource
    private UserSerachDao userdao;
    @Override
    public R search1(String name) {
        QueryWrapper<Ally> wrapper1=new QueryWrapper<>();
        QueryWrapper<RoomHead> wrapper2=new QueryWrapper<>();
            if(name!=null && name.length()>0){
                //模糊查询
                wrapper1.like("allyname","%"+name+"%");
                wrapper2.like("roomname","%"+name+"%");
            }
        List<Ally> list1 = dao.selectList(wrapper1);
        List<RoomHead> list2 = roomdao.selectList(wrapper2);
        List<UserSearchDto> list3 = userdao.userSelectAllBy(name);
        ArrayList<Object> list = new ArrayList<>();
        list.add(list1);
        list.add(list2);
        list.add(list3);
        return Rutils.ok(list);
    }

    @Override
    public R Zuan(int uid) {
        if (uid>0){
            return Rutils.ok(userdao.userZuanSelect(uid));
        }
        return Rutils.fail();
    }

    @Override
    public R selectReMen() {
        return Rutils.ok(userdao.selectReMen());
    }
}
